package com.yaowk.sfp.common.base.model.result;

import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
import java.util.TreeSet;

/**
 * element-ui穿梭框数据结构
 *
 * @param <T>
 * @param <KEY>
 */
public class Transfer<T extends Comparable, KEY> {


    private Set<TransferData> data = new TreeSet<>(new Comparator<TransferData>() {
        @Override
        public int compare(TransferData tTransferData, TransferData t1) {
            return tTransferData.compareTo(t1);
        }
    });
    private Set<KEY> checkedKeys = new HashSet<>();

    public class TransferData implements Comparable<TransferData> {
        private KEY key;
        private String label;
        private boolean disabled;
        private T value;


        public KEY getKey() {
            return key;
        }

        public void setKey(KEY key) {
            this.key = key;
        }

        public String getLabel() {
            return label;
        }

        public void setLabel(String label) {
            this.label = label;
        }

        public boolean isDisabled() {
            return disabled;
        }

        public void setDisabled(boolean disabled) {
            this.disabled = disabled;
        }

        public T getValue() {
            return value;
        }

        public void setValue(T value) {
            this.value = value;
        }

        @Override
        public int compareTo(TransferData transferData) {
            return getValue().compareTo(transferData.getValue());
        }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;

            TransferData that = (TransferData) o;

            if (disabled != that.disabled) return false;
            if (key != null ? !key.equals(that.key) : that.key != null) return false;
            if (label != null ? !label.equals(that.label) : that.label != null) return false;
            return value != null ? value.equals(that.value) : that.value == null;
        }

        @Override
        public int hashCode() {
            int result = key != null ? key.hashCode() : 0;
            result = 31 * result + (label != null ? label.hashCode() : 0);
            result = 31 * result + (disabled ? 1 : 0);
            result = 31 * result + (value != null ? value.hashCode() : 0);
            return result;
        }
    }

    public Transfer() {
    }

    public Set<TransferData> getData() {
        return data;
    }

    public void setData(Set<TransferData> data) {
        this.data = data;
    }

    public Set<KEY> getCheckedKeys() {
        return checkedKeys;
    }

    public void setCheckedKeys(Set<KEY> checkedKeys) {
        this.checkedKeys = checkedKeys;
    }
}
